import { familyAll, familyOne, familyByName } from "@/api/family";

const getDefaultState = () => {
  return {};
};

const state = getDefaultState();

const mutations = {};

const actions = {
  //查看所有科
  async lookFamily({ state }) {
    return new Promise((resolve, reject) => {
      familyAll().then(response => {
        if (response.success) {
          resolve(response.data);
        } else {
          reject(response);
        }
      });
    });
  },
  //查看所有科
  async familyOne({ state }, family) {
    return new Promise((resolve, reject) => {
      familyOne(family).then(response => {
        if (response.success) {
          resolve(response.data);
        } else {
          reject(response);
        }
      });
    });
  },
  //查看所有科
  async familyByName({ state }, name) {
    return new Promise((resolve, reject) => {
      familyByName(name).then(response => {
        if (response.success) {
          resolve(response.data);
        } else {
          reject(response);
        }
      });
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
